<!--
 * @Description: What's this for
 * @Autor: WangYuan
 * @Date: 2022-03-29 14:23:02
 * @LastEditors: WangYuan
 * @LastEditTime: 2022-03-29 14:30:37
-->
<template>
  <el-radio-group
    v-model="modelValue"
    v-if="handleStatusList.length > 0"
    style="margin-bottom: 20px;"
  >
    <el-radio-button label="">全部</el-radio-button>
    <el-radio-button
      v-for="(item, index) in handleStatusList"
      :key="index"
      :label="item.dataValue"
    >
      {{
        item.num > 0 ? item.dataName + '（' + item.num + '）' : item.dataName
      }}
    </el-radio-button>
  </el-radio-group>
</template>
<script>
const statusList = [
  { dataName: '待提交', dataValue: 0, type: 'editNumber' },
  { dataName: '资料校验中', dataValue: 1, type: 'checkingNumber' },
  { dataName: '审核中', dataValue: 2, type: 'auditNumber' },
  { dataName: '已驳回', dataValue: 3, type: 'failNumber' },
  { dataName: '待账户验证', dataValue: 4, type: 'validNumber' },
  { dataName: '待签约', dataValue: 5, type: 'waitSignNumber' },
  { dataName: '已完成', dataValue: 6, type: 'finishNumber' },
  { dataName: '冻结', dataValue: 7, type: 'frozenNumber' }
]
export default {
  name: 'StatusFilter',
  props: ['value', 'query'],
  statusList,
  data () {
    return {
      modelValue: '',
      statusList,
      handleStatusList: []
    }
  },
  watch: {
    modelValue (n) {
      this.$emit('input', n)
    },
    value: {
      immediate: true,
      handler (n) {
        this.modelValue = n || n === 0 ? n : ''
      }
    },
    query: {
      immediate: true,
      deep: true,
      handler (n) {
        this.getApplyMerchantNumber(n)
      }
    }
  },
  methods: {
    getApplyMerchantNumber (query) {
      // this.setNull()
      this.$POST('/sot-admin-api/merchant/applyment/queryApplyMerchantNumber', {
        ...query,
        status: ''
      })
        .then(res => {
          if (res) {
            this.handleStatusList = this.statusList.map(item => {
              item.num = res[item.type]
              return item
            })
          } else {
            this.setNull()
          }
        })
        .catch(_ => {
          this.setNull()
        })
    },
    setNull () {
      this.handleStatusList = this.statusList.map(item => {
        item.num = 0
        return item
      })
    }
  }
}
</script>
